<?php
  
  session_start();
  require_once("Config.php");
  require_once("User.php");
  require_once("MsgStack.php");
  require_once("Util.php");
  
  $msg = new MsgStack();
  
  
  
  if($_GET['action']=="save"){
      
    $user = new User();
    $user->setUsername($_POST['username']);
    $user->setPassword($_POST['password']);
    $user->setRealname($_POST['realname']);
    $user->setEmail($_POST['email']);
    
    $sql = "insert into User Values(null,'".$user->getUsername()."','".$user->getPassword()."','".$user->getRealname()."','".$user->getEmail()."')";
    $res = mysql_query("$sql");
    if($res){
      $msg->push("Insert user successful!");
      $_SESSION['ADD_USER_SUCCESSFUL']=$msg->getMsg();
      header("Location:userManage.php?msg=ADD_USER_SUCCESSFUL");     
      
    }else{
      $msg->push("Cannot insert user!");
      $_SESSION['ADD_USER_SUCCESSFUL']=$msg->getMsg();
      header("Location:userManage.php?msg=ADD_USER_FAILURE"); 
      
    }
            
  }
?>
<html>
  <head>
    <title>
      Add User !
    </title>
    <link href="css/admin-common.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="../js/jquery.js">
    </script>
    <script type="text/javascript" src="js/common.js">
    </script>
  </head>
  <body>
    <h3>User Management : Add User</h3>
    <hr/>
    <p>
      <label>
        <Strong><a href="userManage.html">&lt; Back to User Account List Page</a></Strong>
      </label>
    </p>
    <!--Here is the message from server when page load-->
    <div class="sessionMessage">
    </div>
    <!--Session Message End-->

    <!--Add User Form-->
    <form action="addUser.php" method="post">
      <label>
        <span>RealName:</span>
        <input type="text" id="realname" name="realname"/>
      </label>
      <label>
        <span>UserName:</span>
        <input type="text" id="username" name="username"/>
      </label>
      <label>
        <span>Password:</span>
        <input type="password" id="passwod" name="password" />
      </label>
      <label>
        <span>Password again:</span>
        <input type="password" id="password2" name="password2" />
      </label>
       <label>
        <span>Email:</span>
        <input type="text" id="email" name="email" />
      </label>
      <p>
        <label>
          <span>&nbsp;</span>
       
       <button class="btn btn-style-1" type="submit"><b><b>Submit</b></b></button> </label>
      </p>
    </form>
  </body>
  <script type="text/javascript">
    var app={
      init: function() {
      }

    }
  </script>
</html>
